package com.example.springbootactuator.healthindicator;

import com.example.springbootactuator.service.StatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

/**
 * 自定义 healthIndicator
 * @author ljw
 * @date 2022/10/13 7:36
 */
@Component
public class StatusHealth implements HealthIndicator {

    @Autowired
    private StatusService statusService;

    @Override
    public Health health() {
        String status = statusService.getStatus();
        if (null == status || !status.equals("running")) {
            return Health.down().withDetail("Error", "not running").build();
        }
        return Health.up().build();
    }
}
